home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CAS_App.c
-
- Contains: This is the standard application app.c file. It contains routines
- to implement many things that must be in each application.
-
- Written by: David H Nelson
-
- Copyright © 1993-1995 ComponentWorks, All rights reserved.
-
- Change History (most recent first):
-
- <15> 5/19/95 SJF Bracket all modal dialog calls with CARequestModalFocus.
- App_GetFrontDocWindow uses CAGetFrontDocWindow now.
- --------------------------------------
-
- 05/19/95 SJF Quit crashes when a saved document
- has been opened because a window
- has been inserted in our window list
- that we don't own...
- --------------------------------------
-
- 05/12/95 RB Added stuff for new CALib menu
- Fixed Edit menu selection to be cooperative
- with the ProxyPart
- --------------------------------------
- 05/09/95 SJF Tweaks for WWDC Demo, See previous revision
- if we've trampled on some required changes.
- --------------------------------------
-
- 05/08/95 SJF Don't quit when the last window gets closed
- --------------------------------------
-
- 04/23/95 RB Mods to App_AdjustMenus
- --------------------------------------
- 03/31/95 RB Moved code from App_CloseMenu(), which selects the
- next doc window, into Win_Close().
- --------------------------------------
- 03/29/95 RB Added call to CARegisterFloatingWindow() for the
- Tool palette.
- --------------------------------------
- 03/27/95 DAS converted "theDoc->changed" reference into API call
- --------------------------------------
- 03/16/95 RB CALIB: Changing App_OpenFile to filter for files
- saved using the Bento storage model.
- --------------------------------------
-
- 01/20/95 RB Reworked appAdjustCursor to correctly calculate
- mouseRgn
- --------------------------------------
- 01/18/95 DHN global function and variable name changes to suggest
- OOP design. Split app.c file into app.c, win.c, doc.c,
- item.c, and util.c.
- --------------------------------------
- 01/17/95 DAS changed all FrontWindow() calls to
- App_GetFrontDocWindow() to account for
- floating windows. Added Win_IsToolWindow().
- 1/16/95 DHN Massive improvements including, multiple window
- support, new window offsetting and naming, pref
- file support, file saving/reading, cursor tracking,
- PowerPC support, window update/activate in dialog
- filter, item drawing/selection/cut/copy (not paste),
- drag & drop (no drop yet), window scrolling, get
- info dialog, Select all menu item, Tools menu.
- through
- 12/23/94 DHN Created CASample from existing Light Software
- application framework.
- --------------------------------------
- 1/24/93 DHN Added code to ignore the enter key. Fixed page
- flipping animation by using current GrafPort in
- local coords rather than new GrafPort with global
- coords. Fixed findAgain to actually do something.
- 11/20/93 DHN Created.
- */
-
- #include <Folders.h>
- #include <GestaltEqu.h>
-
- #ifdef USE_CALIB
- #include "CALib.h"
- #include "CAS_CAUtil.h"
- #endif
-
- #include "CAS_Globals.h"
- #include "CAS_App.h"
- #include "CAS_Content.h"
- #include "CAS_Doc.h"
- #include "CAS_Win.h"
- #include "CAS_Event.h"
- #include "CAS_Error.h"
- #include "CAS_AppleEvent.h"
- #include "CAS_Drag.h"
- #include "CAS_ToolPalette.h"
- #include "CAS_Menu.h"
- #include "CAS_MenuItems.h"
- #include "CAS_HelpBalloon.h"
-
- #include <Finder.h>
-
- //----------------------------------------------------------------------
- // local prototypes
-
- #if defined(__cplusplus)
- extern "C"
- {
- #endif
-
- static pascal void scrollBarActionProc(
- ControlHandle theControl,
- short part );
- static pascal long App_GrowZoneProc(
- Size bytesNeeded );
- static pascal OSErr App_BgndMouseDownHandler(
- EventRecord *theEvent,
- short *bgMouseDownOptions );
- static void App_ReadPrefs( void );
- static void App_WritePrefs( void );
- static void App_GetInfoMenu( void );
- static void App_MouseInScrollBars(
- EventRecord *theEvent,
- WindowPtr theWindow );
- static void App_MouseInDocument(
- EventRecord *theEvent,
- WindowPtr theWindow );
- static void App_PreferencesMenu( void );
- static void App_PrintWindow(
- WindowPtr theWindow );
-
- #if defined(__cplusplus)
- }
- #endif
-
- //----------------------------------------------------------------------
-
-
- static pascal void scrollBarActionProc(
- ControlHandle theControl,
- short part )
- {
- DocPtr theDoc;
- short pageSize, scrollAmt, oldValue, newValue;
-
- if ((theControl == nil) || (part == 0))
- return;
-
- theDoc = (DocPtr)GetCRefCon( theControl );
- oldValue = GetControlValue( theControl );
-
- // $$$$$ this should be a full windowful (depending upon horiz or vert)?
- pageSize = 32;
-
- switch (part)
- {
- case inUpButton:
- scrollAmt = -1;
- break;
- case inDownButton:
- scrollAmt = 1;
- break;
- case inPageUp:
- scrollAmt = -pageSize;
- break;
- case inPageDown:
- scrollAmt = pageSize;
- break;
-
- default:
- scrollAmt = 0;
- break;
- }
-
- // if it changed, scroll the contents of the window.
- SetControlValue( theControl, oldValue + scrollAmt );
- newValue = GetControlValue( theControl );
- if (oldValue != newValue)
- {
- // determine which scroll bar it was ( h or v) and scroll appropriately.
- if (theControl == theDoc->hScrollBar)
- Win_Scroll( (**theControl).contrlOwner, oldValue - newValue, 0 );
- else
- Win_Scroll( (**theControl).contrlOwner, 0, oldValue - newValue );
-
- }
- }
-
-
- //---------------------------------------------------------------------------
- // App_CloseAll - Close all the windows (by prompting to save changes. Return false
- // if the user cancels or the window fails to close, true if not.)
-
- Boolean App_CloseAll( void )
- {
- WindowPtr theWindow;
- OSErr theErr;
- Boolean cancelled;
- DocPtr aDoc;
- short i;
-
- for (i = 0; i < kMAXOPENDOCUMENTS; ++i)
- {
- aDoc = gAppPtr->openDocs[i];
-
- if (aDoc != NULL)
- {
- theWindow = Doc_GetWindow (aDoc);
-
- if (theWindow != nil)
- {
- theErr = Win_Close( theWindow, &cancelled );
- if (theErr) Error_ReportOperationError (theErr);
- }
-
- if (cancelled) break;
- }
-
- }
-
- /*
- do
- {
- // DAS: changed from FrontWindow() to App_GetFrontDocWindow.
- theWindow = App_GetFrontDocWindow();
- if (theWindow != nil)
- {
- theErr = Win_Close( theWindow, &cancelled );
- if (theErr) Error_ReportOperationError (theErr);
- }
-
- }
- while ((!cancelled) && (!theErr) && (theWindow != nil));
- */
-
- return (!cancelled);
- }
-
- //---------------------------------------------------------------------------
- static pascal long App_GrowZoneProc(
- Size bytesNeeded )
- {
- // $$$$$ Can't put up a dialog since we may be in the background.
- // What else can we do? Notification Mgr?
- // Dialog_ErrorDialog(itOutOfMemory);
- return 0L;
- }
-
- //---------------------------------------------------------------------------
- // NOT IMPLEMENTED YET
- //
- // We get called here if our app is clicked while in the background. We check
- // to see if the click was in a dragable area. If so, we handle the drag and
- // return EventAlreadyProcessed in bgMouseDownOptions if the drag is to another
- // app, or JustBringToFront if it's in our app. If the click is not in a dragable
- // area, we return JustBringToFront. (Do we ever return BringToFrontAndMouseDown?).
-
- static pascal OSErr App_BgndMouseDownHandler(
- EventRecord *theEvent,
- short *bgMouseDownOptions )
- {
- return noErr;
- }
-
- //---------------------------------------------------------------------------
- // load the prefs from our pref file.
- static void App_ReadPrefs( void )
- {
- FSSpec theSpec;
- FInfo fndrInfo;
- tPrefHandle prefs;
- OSErr theErr;
- short savedRRef;
-
- prefs = nil;
-
- // get name of our pref file
- GetIndString( theSpec.name, kStrings, itOurPrefName );
- theErr =
- FindFolder(
- kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder,
- &theSpec.vRefNum, &theSpec.parID );
- if (theErr != noErr)
- return;
-
- // remember current resource file
- savedRRef = CurResFile();
-
- gPrefRefNum = FSpOpenResFile( &theSpec, fsRdWrPerm );
- if (gPrefRefNum >= 0) // if it opened…
- {
- // make sure the type and creator are ours, else change em.
- theErr = FSpGetFInfo( &theSpec, &fndrInfo );
- if (theErr == noErr)
- {
- if ((fndrInfo.fdCreator != kOurFileCreator) || (fndrInfo.fdType != kOurPrefType))
- {
- fndrInfo.fdCreator = kOurFileCreator;
- fndrInfo.fdType = kOurPrefType;
- theErr = FSpSetFInfo( &theSpec, &fndrInfo );
- }
- }
-
- UseResFile( gPrefRefNum );
-
- prefs = (tPrefHandle)Get1Resource( kPrefResType, kPrefResId );
- }
- else
- {
- gPrefRefNum = 0; // didn't open so init it.
- }
-
- // if we got the prefs and they're the right version, set the pref theDoc from them
- if ((prefs != nil) && ((**prefs).version == kPrefVersion))
- {
- gPrefSampleFlag = (**prefs).prefSampleFlag;
- gCurrentTool = (**prefs).currentTool;
- }
- else // we didn't get our prefs or they were the wrong version, so init the variables.
- {
- gPrefSampleFlag = false;
- gCurrentTool = 0;
- }
-
- if (gPrefRefNum != 0)
- UseResFile( savedRRef );
- }
-
- //---------------------------------------------------------------------------
-
- static void App_WritePrefs( void )
- {
- FSSpec theSpec;
- tPrefHandle prefs;
- Handle tempHandle;
- OSErr theErr;
- short savedRRef;
-
- // if nothing changed
- if (!gPrefChanged)
- {
- // if the pref file was open, close it.
- if (gPrefRefNum != 0)
- {
- CloseResFile( gPrefRefNum );
- gPrefRefNum = 0;
- }
- return;
- }
-
- // remember current resource file
- savedRRef = CurResFile();
-
- // if the pref file did NOT open, try to create one
- if (gPrefRefNum == 0)
- {
- // get name of our pref file
- GetIndString( theSpec.name, kStrings, itOurPrefName );
- theErr =
- FindFolder(
- kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder,
- &theSpec.vRefNum, &theSpec.parID );
- if (theErr != noErr)
- return;
-
- // open failed, so create one
- FSpCreateResFile( &theSpec, kOurFileCreator, kOurPrefType, smRoman ); // use roman script
- // ignore any error here.
-
- // try to open the file
- gPrefRefNum = FSpOpenResFile( &theSpec, fsRdWrPerm );
- // open new file
- // ignore any error here.
- }
-
- // if we got our pref file, save the prefs.
- if (gPrefRefNum != 0)
- {
- UseResFile( gPrefRefNum );
-
- prefs = (tPrefHandle)NewHandleClear( sizeof(tPrefRec) );
-
- // if we got space for the prefs, set them from our theDoc
- if (prefs != nil)
- {
- (**prefs).version = kPrefVersion;
- (**prefs).prefSampleFlag = gPrefSampleFlag;
- (**prefs).currentTool = gCurrentTool;
-
- tempHandle = Get1Resource( kPrefResType, kPrefResId );
- if (tempHandle != nil) // if a prefs resource existed, remove it.
- {
- RmveResource( tempHandle );
- theErr = ResError();
- if (theErr != noErr)
- DEBUGSTR( "\pApp_WritePrefs: we have an error after RmveResource" );
- }
-
- // Add the new prefs and flush the file.
- AddResource( (Handle)prefs, kPrefResType, kPrefResId, "\p" ); // add to the file
- theErr = ResError();
- if (theErr != noErr)
- DEBUGSTR( "\pApp_WritePrefs: error from AddResource" );
- UpdateResFile( gPrefRefNum ); // update resource file
- theErr = ResError();
- if (theErr != noErr)
- DEBUGSTR( "\pApp_WritePrefs: error from UpdateResFile" );
- theErr = FlushVol( nil, 0 ); // flush it out to disk
- if (theErr != noErr)
- DEBUGSTR( "\pApp_WritePrefs: error from FlushVol" );
- }
-
- CloseResFile( gPrefRefNum );
- gPrefRefNum = 0;
-
- UseResFile( savedRRef );
- }
- }
-
- //---------------------------------------------------------------------------
- // App_Init - does any initialization that the app might need including
- // initializing all app specific theDoc.
-
- OSErr App_Init( void )
- {
- OSErr theErr;
- long response, pictCount, i;
-
- // if we're not running system 7 display a message and quit.
- if (!runningSystem7)
- {
- Error_ShowMessage( kCASMsgNotSystem7 );
- return envNotPresent; // a logical choice.
- } // else if we're running earlier than system 7.5, display a message and continue
- else
- {
- theErr = Gestalt( gestaltSystemVersion, &response );
- if ((theErr != noErr) || (response < 0x0750))
- Error_ShowMessage( kCASMsgLessThan75 );
- }
-
- AE_InitAppleEvents();
-
- gGrowZoneUPP = NewGrowZoneProc( App_GrowZoneProc );
- SetGrowZone( gGrowZoneUPP );
-
- #ifdef THINK_C
- // install the drag handlers and the background mouse down handler
- if (hasDragMgr)
- SetBgndMouseHandler( &App_BgndMouseDownHandler );
- #endif
-
- gWindowEventFilterUPP = NewModalFilterProc( bWindowEventFilter );
- gWindowEventFilterYDUPP = NewModalFilterYDProc( bWindowEventYDFilter );
- gScrollBarActionUPP = NewControlActionProc( scrollBarActionProc );
- gDragReceiveHandlerUPP = NewDragReceiveHandlerProc( Drag_DragReceiveHandler );
- gDragTrackingHandlerUPP = NewDragTrackingHandlerProc( Drag_DragTrackingHandler );
-
- #ifdef USE_CALIB
-
- gDragSendProcUPP = NewDragSendDataProc (Drag_DragSendDataProc);
- // 3/16 RB - For custom save dialog
- gDlgHookYDUPP = NewDlgHookYDProc( CASaveDialogHook );
-
- #endif
-
- gSplatsnd = GetResource( 'snd ', 128 );
-
- pictCount = 4;
- for (i=0; i<pictCount; i++)
- gItemPICT[i] = GetPicture( 1000 + i );
-
- App_ReadPrefs();
-
- gCurrentTool = 0;
- (void)ToolPalette_Create( gItemPICT, pictCount, gCurrentTool );
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- CARegisterFloatingWindow (ToolPalette_VerifyWindow(NULL));
- if (theErr = CAError())
- ; // handle the error
- }
- #endif
-
- gAppPtr = (AppPtr) NewPtr (sizeof (AppRecord));
- gAppPtr->openDocCount = 0;
-
- for (i = 0; i < kMAXOPENDOCUMENTS; ++i)
- gAppPtr->openDocs[i] = NULL;
-
- return noErr;
- }
-
-
- //---------------------------------------------------------------------------
- void App_LogOpenDocument (DocPtr theDoc)
- {
- short i = 0;
-
- while (gAppPtr->openDocs[i] != NULL) ++i;
-
- gAppPtr->openDocs[i] = theDoc;
- gAppPtr->openDocCount += 1;
-
- }
-
- //---------------------------------------------------------------------------
- void App_LogCloseDocument (DocPtr theDoc)
- {
- short i;
-
- for (i = 0; i < kMAXOPENDOCUMENTS; ++i)
- {
- if (gAppPtr->openDocs[i] == theDoc)
- {
- gAppPtr->openDocs[i] = NULL;
- gAppPtr->openDocCount -= 1;
- break;
- }
- }
-
-
- }
-
- //---------------------------------------------------------------------------
- // App_SetUpMenus - insert any application menus
-
- void App_SetUpMenus( void )
- {
- MenuHandle theMenu;
-
- theMenu = GetMenu( kToolMenu );
- if (theMenu != nil)
- InsertMenu( theMenu, 0 );
-
- }
-
- //---------------------------------------------------------------------------
- // appQuit - clean up before quitting. Reverse any actions from App_Init.
-
- void App_Quit( void )
- {
- App_WritePrefs(); // save our prefs
-
- ToolPalette_Dispose( nil );
-
- DisposeRoutineDescriptor( gGrowZoneUPP );
-
- DisposeRoutineDescriptor( gWindowEventFilterUPP );
- DisposeRoutineDescriptor( gWindowEventFilterYDUPP );
- DisposeRoutineDescriptor( gScrollBarActionUPP );
- DisposeRoutineDescriptor( gDragReceiveHandlerUPP );
- DisposeRoutineDescriptor( gDragTrackingHandlerUPP );
-
- AE_DisposeAppleEvents();
-
- DisposePtr ((Ptr) gAppPtr);
-
- }
-
- //---------------------------------------------------------------------------
- // App_Idle - called during idle time when there is no event
-
- void App_Idle(
- WindowPtr theWindow )
- {
- // NOTE: remove the #ifdef if any working code is placed here!
-
- #pragma unused (theWindow)
-
- #if 0
- GrafPtr savePort;
-
- GetPort( &savePort );
-
- if (theWindow != nil)
- SetPort( theWindow );
-
- // Do any idle work here:
- // call TEIdle if using Text Edit.
-
- SetPort( savePort );
- #endif
- }
-
- //---------------------------------------------------------------------------
- // Adjust the cursor depending on theLoc (global coords). Copy the region in
- // which the cursor will not change into the existing region theRgn. Assume
- // that we are not in the background when we get called here.
-
- void App_AdjustCursor(
- WindowPtr theWindow,
- Point theLoc,
- RgnHandle theRgn )
- {
- DocPtr theDoc;
- RgnHandle arrowRgn, itemsRgn;
- WindowPtr toolWindow, appWindow;
- GrafPtr savePort;
- Rect theRect;
- ElemPtr elem;
- short elemPart;
- CursPtr defaultCursor;
- Point localPoint;
-
- if (gCurrentTool == 0)
- defaultCursor = &qd.arrow;
- else
- defaultCursor = *GetCursor( crossCursor );
-
- theDoc = nil;
-
- arrowRgn = NewRgn();
- //SetRectRgn( arrowRgn, -0x7FFE, -0x7FFE, 0x7FFE, 0x7FFE );
- SetRectRgn( arrowRgn, 0, 0, 1, 1 );
-
- // make sure there is a window and it's ours
- if (!Win_IsAppWindow( theWindow ))
- {
- CopyRgn( arrowRgn, theRgn );
- SetCursor( &qd.arrow );
- }
- else
- {
- // Check if the mouse is in the ToolPalette
- toolWindow = ToolPalette_GetWindow();
-
- CopyRgn( ((WindowPeek)theWindow)->strucRgn, arrowRgn );
- InsetRgn( arrowRgn, 16, 16 );
-
- // is the mouse in the tool pallete?
- if (PtInRgn( theLoc, ((WindowPeek)toolWindow)->strucRgn ))
- {
- SetCursor( &qd.arrow );
- CopyRgn( ((WindowPeek)toolWindow)->strucRgn, theRgn );
- }
- else if (PtInRgn( theLoc, ((WindowPeek)theWindow)->strucRgn))
- {
- // get the contentRect into theRgn.
-
- // get the window theDoc.
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- GetPort( &savePort );
- SetPort( theWindow );
-
- localPoint = theLoc;
- GlobalToLocal( &localPoint );
-
- elemPart = ElemColl_FindElem(theDoc->contentColl, localPoint, &elem);
-
- if (elem)
- {
- if (Elem_GetSelected(elem))
- {
- if (elemPart == inElement)
- {
- SetCursor( *GetCursor( handCursor ));
- Elem_GetLocatedRect (elem, &theRect);
- Doc_RectDocToGlobal( theDoc, &theRect );
- RectRgn( theRgn, &theRect );
-
- }
- if ((elemPart == inCornerResize) ||
- (elemPart == inEdgeResize))
- {
- SetCursor( &qd.arrow );
- CopyRgn (elem->selRgn.cornerHandleRgn, theRgn);
- UnionRgn (elem->selRgn.edgeHandleRgn, theRgn, theRgn);
- }
- }
- else
- {
- SetCursor( &qd.arrow );
- Elem_GetLocatedRect (elem, &theRect);
- Doc_RectDocToGlobal( theDoc, &theRect );
- RectRgn( theRgn, &theRect );
-
- }
-
- }
- #ifdef USE_CALIB
-
- else if (CAActiveBorderContainsPoint (theLoc))
- {
- CopyRgn( ((WindowPeek)theWindow)->strucRgn, theRgn );
- SetCursor( *GetCursor( handCursor ));
- }
-
- #endif
- else if (!PtInRgn( theLoc, arrowRgn ))
- {
- // mouse Rgn is the non-content part of the window
- CopyRgn( ((WindowPeek)theWindow)->strucRgn, theRgn );
- DiffRgn( theRgn, arrowRgn, theRgn );
-
- // Subtract the ToolPalette Rgn
- toolWindow = ToolPalette_GetWindow();
- DiffRgn( theRgn, ((WindowPeek)toolWindow)->strucRgn, theRgn );
-
- SetCursor( &qd.arrow );
- }
- else
- {
- itemsRgn = NewRgn();
-
- RectRgn( theRgn, &theDoc->contentRect );
- RgnLocalToGlobal( theRgn );
-
- // Subtract the ToolPalette Rgn
- toolWindow = ToolPalette_GetWindow();
- if (toolWindow != nil)
- DiffRgn( theRgn, ((WindowPeek)toolWindow)->strucRgn, theRgn );
-
- Doc_CalcContentElemRgn( theDoc, itemsRgn );
- Doc_RgnDocToGlobal( theDoc, itemsRgn );
-
- DiffRgn( theRgn, itemsRgn, theRgn );
-
- DisposeRgn( itemsRgn );
- SetCursor (defaultCursor);
-
- }
-
- SetPort( savePort );
- }
- else // Mouse is not in the front doc or the tool palette window
- {
- SetCursor( &qd.arrow );
- CopyRgn( LMGetGrayRgn(), theRgn );
-
- // Subtract the front doc window Rgn and the tool palette Rgn
- appWindow = App_GetFrontDocWindow();
- DiffRgn( theRgn, ((WindowPeek)appWindow)->strucRgn, theRgn );
-
- toolWindow = ToolPalette_GetWindow();
- DiffRgn( theRgn, ((WindowPeek)toolWindow)->strucRgn, theRgn );
- }
- }
-
- DisposeRgn( arrowRgn );
- }
-
- //---------------------------------------------------------------------------
-
- void App_AdjustMenus(
- WindowPtr theWindow )
- {
- Boolean selectionExists;
- DocPtr theDoc;
- MenuHandle targetMenuH;
- long result, scrapOffset, i;
- Boolean bWin_IsAppWindow;
-
- bWin_IsAppWindow = Win_IsAppWindow( theWindow );
- if (bWin_IsAppWindow)
- {
- theDoc = (DocPtr)GetWRefCon( theWindow );
- selectionExists = Doc_SelectionExists( theDoc );
-
- }
- else
- {
- theDoc = nil;
- selectionExists = false;
- }
-
- // enable the save menu if there is a doc and (it has changed or never been saved).
- targetMenuH = GetMenuHandle( kFileMenu );
- mhSetMenuItem(bWin_IsAppWindow && (Doc_GetDirty( theDoc )
- || (theDoc->fileRefNum <= 0)), targetMenuH, kSaveItem );
-
- // SaveAs
- mhSetMenuItem(bWin_IsAppWindow, targetMenuH, kSaveAsItem );
- //mhSetMenuItem(false, targetMenuH, kSaveAsItem );
-
- // Close
- mhSetMenuItem(true, targetMenuH, kCloseItem );
-
- #ifdef USE_CALIB
- // enable the GetInfo menu if there is a doc
- mhSetMenuItem( bWin_IsAppWindow, targetMenuH, kDocumentInfoItem );
- #else
- // enable the GetInfo menu if there is a doc
- mhSetMenuItem( bWin_IsAppWindow, targetMenuH, kGetInfoItem );
- #endif
-
- result = GetScrap( nil, kPICTType, &scrapOffset );
-
- #ifdef USE_CALIB
-
- if (gCALibExists)
- {
-
- result = ((InfoScrap())->scrapSize > 0) ? 1 : -1;
-
- #if !CALIB_FRIENDLY_DATA_TRANSFER
- #if 0
- // Check if the OpenDoc clipboard has content
- if (!result)
- {
- CADocumentRef clipDoc;
-
- clipDoc = CAGetClipboardDocument(theDoc, kCACloneCopy);
- if (CAGetSize(clipDoc))
- result = true;
- CACloseDocument (clipDoc);
- }
- #endif
- #endif
-
- if (!bWin_IsAppWindow)
- {
- mhSetMenuItem( bWin_IsAppWindow, targetMenuH, kInsertItem );
- }
- else
- {
-
- if (theDoc->partDocRef == gFocusDocument)
- {
-
- mhSetMenuItem( bWin_IsAppWindow, targetMenuH, kInsertItem );
-
- mhSetMenuItem( (Doc_GetSelectedFrameCount(theDoc) == 1), targetMenuH,
- kOpenSelectionItem);
-
- targetMenuH = GetMenuHandle( kEditMenu );
-
- mhSetMenuItem( selectionExists && !theDoc->fileLocked, targetMenuH, kCutItem );
- mhSetMenuItem( selectionExists, targetMenuH, kCopyItem );
- mhSetMenuItem( selectionExists && !theDoc->fileLocked, targetMenuH, kClearItem );
- mhSetMenuItem( (result > 0) && (theDoc != nil) && !theDoc->fileLocked, targetMenuH, kPasteItem );
-
- // enable the selectAll menu if there are any items in the document.
- mhSetMenuItem( bWin_IsAppWindow && (ElemColl_GetCount (theDoc->contentColl) > 0), targetMenuH, kSelectAllItem );
-
- mhSetMenuItem( (Doc_GetSelectedFrameCount(theDoc) == 1), targetMenuH,
- kPartInfoItem);
-
- mhSetMenuItem( false, targetMenuH, kViewInWindowItem );
-
- // check the current tool menu item.
- targetMenuH = GetMenuHandle( kToolMenu );
- if (targetMenuH)
- {
- for (i=1; i <= kTool4; i++)
- CheckItem( targetMenuH, i, i == gCurrentTool+1 );
- }
-
- }
- else
- {
-
- targetMenuH = GetMenuHandle( kEditMenu );
- mhSetMenuItem( true, targetMenuH, kViewInWindowItem );
-
- }
-
- }
- }
- else
- {
- targetMenuH = GetMenuHandle( kEditMenu );
-
- mhSetMenuItem( selectionExists && !theDoc->fileLocked, targetMenuH, kCutItem );
- mhSetMenuItem( selectionExists, targetMenuH, kCopyItem );
- mhSetMenuItem( (result > 0) && (theDoc != nil) && !theDoc->fileLocked, targetMenuH, kPasteItem );
- mhSetMenuItem( selectionExists && !theDoc->fileLocked, targetMenuH, kClearItem );
-
- // enable the selectAll menu if there are any items in the document.
- mhSetMenuItem( bWin_IsAppWindow && (ElemColl_GetCount (theDoc->contentColl) > 0), targetMenuH, kSelectAllItem );
-
- // check the current tool menu item.
- targetMenuH = GetMenuHandle( kToolMenu );
- for (i=1; i <= kTool4; i++)
- CheckItem( targetMenuH, i, i == gCurrentTool+1 );
- }
-
- #else
-
- mhSetMenuItem( selectionExists && !theDoc->fileLocked, targetMenuH, kCutItem );
- mhSetMenuItem( selectionExists, targetMenuH, kCopyItem );
- mhSetMenuItem( (result > 0) && (theDoc != nil) && !theDoc->fileLocked, targetMenuH, kPasteItem );
- mhSetMenuItem( selectionExists && !theDoc->fileLocked, targetMenuH, kClearItem );
-
- // enable the selectAll menu if there are any items in the document.
- mhSetMenuItem( bWin_IsAppWindow && (ElemColl_GetCount (theDoc->contentColl) > 0), targetMenuH, kSelectAllItem );
-
- // check the current tool menu item.
- targetMenuH = GetMenuHandle( kToolMenu );
- for (i=1; i <= kTool4; i++)
- CheckItem( targetMenuH, i, i == gCurrentTool+1 );
-
- #endif
-
- }
-
- //---------------------------------------------------------------------------
-
- static void App_GetInfoMenu( void )
- {
- GrafPtr savePort;
- DialogPtr theDialog;
- WindowPtr aWindow;
- DocPtr theDoc;
- Str63 countStr;
- Str63 selectedCountStr;
- Str63 docTitle;
- long selectedItemCount, i;
-
- #if 0
- GetPort( &savePort );
- aWindow = App_GetFrontDocWindow();
-
- theDoc = (DocPtr)GetWRefCon( aWindow );
-
- NumToString( ElemColl_GetCountOfType (theDoc->contentColl, kPICTType), countStr );
-
- selectedItemCount = 0;
- for (i=0; i<ElemColl_GetCount (theDoc->contentColl); ++i)
- if (theDoc->itemArray[i].selected)
- ++selectedItemCount;
-
- NumToString( selectedItemCount, selectedCountStr );
-
- Dialog_CenterDLOGonFrontWindow( kGetInfoDialog );
- theDialog = GetNewDialog( kGetInfoDialog, nil, nil /* INFRONT */ );
-
- if (theDialog == nil)
- return;
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- if (!CARequestModalFocus( (WindowPtr)aWindow ))
- {
- DisposeDialog( theDialog );
- return;
- }
- }
- #endif
-
- SetPort( theDialog );
-
- // ( void )Win_CenterWindowOnParentWindow( (WindowPtr)theDialog );
- Dialog_OutlineButton( theDialog, 1 );
- Dialog_SetTextItem( theDialog, 5, countStr );
- Dialog_SetTextItem( theDialog, 6, selectedCountStr );
-
- GetWTitle( (WindowPtr)theDialog, docTitle );
- Dialog_SetTextItem( theDialog, 4, docTitle );
-
- App_ForceActivateFrontWindow( false );
- SelectWindow( (WindowPtr)theDialog );
-
- iOKITEM = iCancelITEM = kOKButton;
- do
- {
- ModalDialog( gWindowEventFilterUPP, &itemHit );
- }
- while (itemHit != kOKButton);
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- OSErr theErr;
-
- CARelinquishModalFocus( (WindowPtr)aWindow );
- if (theErr = CAError())
- ; // handle the error
- }
- #endif
-
- DisposeDialog( theDialog );
- App_ForceActivateFrontWindow( true );
-
- SetPort( savePort );
-
- #endif
- }
-
- //---------------------------------------------------------------------------
- // Handle application specific file menu items here.
-
- void App_HandleFileMenu(
- short menuItem,
- WindowPtr theWindow )
- {
- #pragma unused (theWindow)
-
- switch (menuItem)
- {
- #ifdef USE_CALIB
- case kDocumentInfoItem:
- #else
- case kGetInfoItem:
- #endif
- App_GetInfoMenu();
- break;
-
- default:
- break;
- }
- }
-
- //---------------------------------------------------------------------------
- // Handle application specific edit menu items here.
-
- void App_HandleEditMenu(
- short menuItem,
- WindowPtr theWindow )
- {
- #pragma unused (theWindow)
-
- switch (menuItem)
- {
- case kPreferencesItem:
- App_PreferencesMenu();
- break;
-
- default:
- break;
- }
- }
-
- //---------------------------------------------------------------------------
- // Handle application specific edit menu items here.
-
- void App_HandleToolMenu(
- short menuItem,
- WindowPtr theWindow )
- {
- #pragma unused (theWindow)
-
- switch (menuItem)
- {
- case kTool1:
- case kTool2:
- case kTool3:
- case kTool4:
- gCurrentTool = menuItem - 1;
- ToolPalette_SetSelectedCell( nil, gCurrentTool );
- gPrefChanged = true;
- break;
-
- default:
- break;
- }
- }
-
- //---------------------------------------------------------------------------
- // Handle application specific menus & items here.
-
- void App_HandleMenu(
- long mSelect,
- WindowPtr theWindow )
- {
- short menuID;
-
- menuID = HiWord( mSelect );
- switch (menuID)
- {
- case kToolMenu:
- App_HandleToolMenu( mSelect, theWindow );
- break;
-
- default:
- break;
- }
- }
-
- //---------------------------------------------------------------------------
- // do anything that needs to be done when our window is activated.
-
- void App_Activate(
- WindowPtr theWindow )
- {
- DocPtr theDoc;
-
- // if there is no window or it's not our window, get out.
- if (!Win_IsAppWindow( theWindow ))
- return;
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
- SetPort(theWindow );
-
- #ifdef USE_CALIB
- CAUtil_InvalSelRgns (theDoc);
- #endif
-
- // This is the hiding the scroll bars method.
- if (theDoc)
- {
- ShowControl( theDoc->hScrollBar );
- ShowControl( theDoc->vScrollBar );
- }
-
- HiliteWindow (theWindow, true);
- DrawGrowIcon( theWindow );
-
- }
-
- //---------------------------------------------------------------------------
- // do anything that needs to be done when our window is deactivated.
-
- void App_Deactivate(
- WindowPtr theWindow )
- {
- GrafPtr savePort;
- DocPtr theDoc;
-
- // if there is no window or it's not our window, get out.
- if (!Win_IsAppWindow( theWindow ))
- return;
-
- // NOTE: during window creation, the new window shows up in the
- // window list but hasn't been fully initialized by us yet, so
- // theDoc comes up NIL.
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- #ifdef USE_CALIB
-
- GetPort( &savePort );
- SetPort( theWindow );
- CAUtil_InvalSelRgns (theDoc);
- SetPort( savePort );
-
- #endif
-
- // This is the hiding the scroll bars method.
- if (theDoc)
- {
- HideControl( theDoc->hScrollBar );
- HideControl( theDoc->vScrollBar );
- }
-
- HiliteWindow (theWindow, false);
- DrawGrowIcon( theWindow );
-
- }
-
- //---------------------------------------------------------------------------
- // handle resume event.
-
- void App_Resume( void )
- {
- // set the sleep time short so we get called often
- // but not so short that other apps don't get time.
- gSleepTime = GetCaretTime();
-
- // activate our front window.
- // DAS: changed from FrontWindow() to App_GetFrontDocWindow()
- App_Activate( App_GetFrontDocWindow() );
- }
-
- //---------------------------------------------------------------------------
- // handle suspend event.
-
- void App_Suspend( void )
- {
- WindowPtr frontWindow;
-
- // set the sleep time long since we don't need to be called
- // very often when we're in the background.
- gSleepTime = 0x7FFFFFFF;
-
- // deactivate our front window.
- // DAS: changed from FrontWindow() to App_GetFrontDocWindow()
-
- #ifdef USE_CALIB
- #if !CALIB_FRIENDLY_DATA_TRANSFER
- CAExportClipboard ();
- #endif
- #endif
-
- frontWindow = App_GetFrontDocWindow();
-
- if (Win_IsAppWindow( frontWindow ))
- {
-
- App_Deactivate(frontWindow);
-
- }
-
- }
-
- //---------------------------------------------------------------------------
- // draw our window's contents
-
- void App_Update(
- WindowPtr theWindow )
- {
- RgnHandle saveClip;
- DocPtr theDoc;
- Rect theRect;
- GrafPtr savePort;
- Point saveOrigin;
- short baseH, baseV;
-
- // if there is no window or it's not ours, get out.
- if (!Win_IsAppWindow( theWindow ))
- return;
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- GetPort( &savePort );
- SetPort( theWindow );
-
- // save the ClipRgn
- saveClip = NewRgn();
- GetClip( saveClip );
-
- DrawGrowIcon( theWindow );
- DrawControls( theWindow );
-
- // move the coordinate system according to the scroll bars.
- GetOrigin( &saveOrigin );
- Doc_SetGrafOrigin( theDoc );
-
- #ifndef USE_CALIB
- // clip to everything but the scroll bars and grow box.
- theRect = theDoc->contentRect;
- baseH = GetControlValue( theDoc->hScrollBar );
- baseV = GetControlValue( theDoc->vScrollBar );
- OffsetRect( &theRect, baseH, baseV );
- ClipRect( &theRect );
- #else
- {
- // For the CALib version also add the area used by
- // frames to the clip
-
- //clipRgn = NewRgn();
- theRect = theDoc->contentRect;
- baseH = GetControlValue( theDoc->hScrollBar );
- baseV = GetControlValue( theDoc->vScrollBar );
- OffsetRect( &theRect, baseH, baseV );
- ClipRect( &theRect );
-
- }
- #endif
-
- EraseRect( &theDoc->contentRect );
-
- // draw the content area here.
- Doc_Draw( theDoc );
-
- // set the coordinate system back.
- // put the clipRgn back and get rid of the saved rgn.
- SetOrigin( saveOrigin.h, saveOrigin.v );
- SetClip( saveClip );
- DisposeRgn( saveClip );
-
- SetPort( savePort );
-
- }
-
- //----------------------------------------------------------------------
- // Called after the window is moved. Assume the window is a doc window.
-
- void App_Drag(
- WindowPtr theWindow )
- {
- Win_AdjustStdState( theWindow );
- }
-
- //----------------------------------------------------------------------
- // Called after the window is resized.
-
- void App_Grow(
- WindowPtr theWindow )
- {
- // EraseRect(&theWindow->portRect);
- // InvalRect(&theWindow->portRect);
- Win_Adjust( theWindow );
- Win_AdjustStdState( theWindow );
- }
-
- //----------------------------------------------------------------------
- // Called after the window is zoomed in (smaller).
-
- void App_ZoomIn(
- WindowPtr theWindow )
- {
- Win_CheckWindowPosition( theWindow );
- Win_AdjustStdState( theWindow );
- Win_Adjust( theWindow );
- }
-
- //----------------------------------------------------------------------
- // Called after the window is zoomed out (larger).
-
- void App_ZoomOut(
- WindowPtr theWindow )
- {
- Win_CheckWindowPosition( theWindow );
- Win_AdjustStdState( theWindow );
- Win_Adjust( theWindow );
- }
-
- //----------------------------------------------------------------------
- // handle key presses.
-
- void App_Key(
- WindowPtr theWindow,
- short code,
- short modifiers )
- {
- #pragma unused (modifiers)
-
- DocPtr theDoc;
- short key, ctlValue;
-
- // if there is no window or it's not ours, get out.
- if (!Win_IsAppWindow( theWindow ))
- return;
-
- theDoc = (DocPtr)GetWRefCon(theWindow);
-
- key = (code & keyCodeMask) >> 8;
- code = code & charCodeMask;
-
- // $$$$$ if we don't update the window before scrolling it, we'll get
- // left over white space from the balloon.
- hideBalloons(theWindow); // reset the balloons since the selection could be moving.
-
- switch (code)
- {
- case kHome:
- ctlValue = GetControlValue( theDoc->vScrollBar );
- SetControlValue( theDoc->vScrollBar, GetControlMinimum( theDoc->vScrollBar ) );
- Win_Scroll( theWindow, 0, ctlValue - GetControlMinimum( theDoc->vScrollBar ) );
- break;
-
- case kEnd:
- ctlValue = GetControlValue( theDoc->vScrollBar );
- SetControlValue( theDoc->vScrollBar, GetControlMaximum( theDoc->vScrollBar ) );
- Win_Scroll( theWindow, 0, ctlValue - GetControlMaximum( theDoc->vScrollBar ) );
- break;
-
- case kPageUp:
- case kPageDown:
- scrollBarActionProc( theDoc->vScrollBar, (code == kPageUp) ? inPageUp : inPageDown );
- break;
-
- case kLeftArrow:
- Doc_MoveSelection( theDoc, -1, 0 );
- break;
-
- case kRightArrow:
- Doc_MoveSelection( theDoc, 1, 0 );
- break;
-
- case kUpArrow:
- Doc_MoveSelection( theDoc, 0, -1 );
- break;
-
- case kDownArrow:
- Doc_MoveSelection( theDoc, 0, 1 );
- break;
-
- case kDelete:
- Doc_ClearMenu( theDoc ); // clear the selection.
- break;
-
- case kEscape:
- // clear and escape share same char code so check the key code
- if (key == 0x47) // if there is a selection, clear maps to clear menu.
- Doc_ClearMenu( theDoc ); // clear the selection.
- break;
-
- case kEnter: // ignore the enter key.
- break;
-
- case kFunctionKeys:
- // function keys (F1-F4) all share the same char code so check the key.
- switch (key)
- {
- case 0x7A:
- Doc_UndoMenu( theDoc );
- break;
- case 0x78:
- Doc_CutMenu( theDoc );
- break;
- case 0x63:
- Doc_CopyMenu( theDoc, false );
- break;
- case 0x76:
- Doc_PasteMenu( theDoc );
- break;
-
- default:
- break;
- }
- break;
-
- default: // all other key strokes are handled here.
- break;
- }
- }
-
- //----------------------------------------------------------------------
- // handle command key presses.
-
- void App_CmdKey(
- WindowPtr theWindow,
- short code,
- short modifiers )
- {
- #pragma unused (modifiers)
-
- // if there is no window or it's not ours, get out.
- if (!Win_IsAppWindow( theWindow ))
- return;
-
- // strip off any keyCode.
- code = code & charCodeMask;
-
- // $$$$$ if we don't update the window before scrolling it, we'll get
- // left over white space from the balloon.
- // reset the balloons since the selection could be moving.
- hideBalloons( theWindow );
-
- switch (code)
- {
- case kLeftArrow:
- break;
- case kRightArrow:
- break;
- case kUpArrow:
- break;
- case kDownArrow:
- break;
-
- default:
- break;
- }
- }
-
- //---------------------------------------------------------------------------
- // called when there is a mouse down in the scroll bars of an app window.
-
- static void App_MouseInScrollBars(EventRecord *theEvent, WindowPtr theWindow)
- {
- Point thePt;
- short thePart, newValue, oldValue;
- ControlHandle theControl;
- DocPtr theDoc;
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- thePt = theEvent->where;
- GlobalToLocal( &thePt );
-
- // find the control clicked on
- thePart = FindControl( thePt, theWindow, &theControl );
- if ((theControl != nil) && (thePart != 0))
- {
- // click on scroll bar
- if ((theControl == theDoc->hScrollBar) || (theControl == theDoc->vScrollBar))
- {
- if (thePart == inThumb) // track the thumb
- {
- // get previous setting
- oldValue = GetControlValue( theControl );
- thePart = TrackControl( theControl, thePt, nil );
- newValue = GetControlValue( theControl );
-
- // if the scroll bar changed, scroll the window contents.
- if (oldValue != newValue)
- {
- // determine which scroll bar it was ( h or v) and scroll appropriately.
- if (theControl == theDoc->hScrollBar)
- Win_Scroll( theWindow, oldValue - newValue, 0 );
- else
- Win_Scroll( theWindow, 0, oldValue - newValue );
- }
- }
- else
- {
- /* track arrows or page up/down */
- thePart = TrackControl( theControl, thePt, gScrollBarActionUPP );
- }
- }
- }
- }
-
- //---------------------------------------------------------------------------
- // called when there is a mouse down in document area of an app window.
-
- static void App_MouseInDocument(
- EventRecord *theEvent,
- WindowPtr theWindow )
- {
- Point thePt;
- RgnHandle saveClip;
- GrafPtr savePort;
- Rect theRect;
- Point docPt;
- DocPtr theDoc;
- Point saveOrigin;
- ElemPtr elem;
- short elemPart;
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- GetPort (&savePort);
- SetPort (theWindow);
-
- thePt = theEvent->where;
- GlobalToLocal( &thePt );
-
- // move the coordinate system according to the scroll bars
- GetOrigin( &saveOrigin );
- Doc_SetGrafOrigin( theDoc );
-
- // get the point again and adjust for our coord system.
- docPt = theEvent->where;
- GlobalToLocal( &docPt );
-
- // set the coordinate system back.
- SetOrigin( saveOrigin.h, saveOrigin.v );
-
- // $$$$$ if we don't update the window before scrolling it, we'll get
- // left over white space from the balloon.
- // reset the balloons since the selection could be moving.
- hideBalloons( theWindow );
-
- elemPart = ElemColl_FindElem(theDoc->contentColl, docPt, &elem);
-
- if (elem)
- {
-
- if (elemPart == inElement)
- {
- Elem_HandleMouseDown (elem, theDoc, theEvent);
- }
- else if (elemPart == inCornerResize)
- {
- Elem_HandleMouseInCornerResize (elem, theDoc, &docPt, theEvent);
- SetRectRgn( gMouseRgn, 0, 0, 1, 1 );
- }
- else if (elemPart == inEdgeResize)
- {
- Elem_HandleMouseInEdgeResize (elem, theDoc, &docPt, theEvent);
- SetRectRgn( gMouseRgn, 0, 0, 1, 1 );
- }
-
- }
-
- // we made it this for so we must be creating a new item.
-
- else if (gCurrentTool == 0)
- {
- // If we're not focused, get the focus and that's all
- if (gFocusDocument != theDoc->partDocRef)
- CARequestStandardFocusSet (theWindow);
- else
- {
- Doc_SelectAllElements( theDoc, false );
- theDoc->insertionPoint = docPt;
- Doc_HandleSelectionRect (theDoc, theEvent->where);
- }
- }
- else
- {
- if (gFocusDocument != theDoc->partDocRef)
- CARequestStandardFocusSet (theWindow);
- else
- {
- // If anything is selected then deselect everything
- if (Doc_SelectionExists(theDoc))
- {
- // make sure none of the items are selected
- Doc_SelectAllElements( theDoc, false );
- }
- // else add a PICT element according to the current tool
- else
- {
- // save the ClipRgn
- saveClip = NewRgn();
- GetClip( saveClip );
-
- // move the coordinate system according to the scroll bars.
- SetOrigin(
- GetControlValue( theDoc->hScrollBar ),
- GetControlValue( theDoc->vScrollBar ) );
-
- // clip to everything but the scroll bars and grow box
- theRect = theDoc->contentRect;
- OffsetRect(
- &theRect,
- GetControlValue( theDoc->hScrollBar ),
- GetControlValue( theDoc->vScrollBar ) );
- ClipRect( &theDoc->contentRect );
-
- // add the item to our document.
- Doc_AddItemPict( theDoc, gItemPICT[gCurrentTool], docPt );
-
- // set the coordinate system back.
- SetOrigin( saveOrigin.h, saveOrigin.v );
-
- // put the clipRgn back and get rid of the saved rgn.
- SetClip( saveClip );
- DisposeRgn( saveClip );
- Doc_SetDirty( theDoc, true );
- }
- }
- }
-
- SetPort (savePort);
-
- }
-
- //---------------------------------------------------------------------------
- // called when there is a mouse down in the content region of an app window.
- void App_MouseInContent(
- EventRecord *theEvent,
- WindowPtr theWindow )
- {
- Point thePt;
- DocPtr theDoc;
- Rect docRect;
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- docRect = theDoc->contentRect;
- RectLocalToGlobal( &docRect );
- thePt = theEvent->where;
-
- // if it's in the main part of the document, handle it
- if (PtInRect( thePt, &docRect ))
- App_MouseInDocument( theEvent, theWindow );
- else // otherwise it must be in the scroll bars
- App_MouseInScrollBars( theEvent, theWindow );
- }
-
- //---------------------------------------------------------------------------
- // File Menu Items
- //---------------------------------------------------------------------------
- // App_NewMenu - create a new document.
-
- void App_NewMenu( void )
- {
- OSErr theErr;
-
- theErr = Doc_New();
- if (theErr) Error_ReportOperationError (theErr);
-
- }
-
- //---------------------------------------------------------------------------
- // App_OpenMenu - allow the user to select a file. then open the file.
-
- void App_OpenMenu( void )
- {
- SFTypeList theTypeList;
- StandardFileReply theReply;
- Point thePt;
- OSErr theErr = noErr;
- short numTypes = 1;
- FInfo fInfo;
-
- theTypeList[0] = kOurFileType;
-
- #ifdef USE_CALIB
- theTypeList[1] = kContainerFileType;
- numTypes = 2;
- #endif
-
- if (!CARequestModalFocus( NULL))
- return;
-
- thePt.h = thePt.v = -1; // center on the screen.
- CustomGetFile(
- nil, numTypes, theTypeList, &theReply, 0, thePt, nil,
- gWindowEventFilterYDUPP, nil, nil, nil );
-
- CARelinquishModalFocus( NULL );
-
- if (theReply.sfGood)
- {
- FSpGetFInfo (&theReply.sfFile, &fInfo);
-
- #ifdef STATIONERY
- if (fInfo.fdFlags & kIsStationery)
- {
-
- // stationary pad - create new file
- page = theReply.sfFile;
- MakeDatedUniqueFSSpec (&page);
- CopyFile (&theReply.sfFile, &page);
- theErr = Doc_Open( &page ); // $$$$$ don't forget to handle errors.
-
- }
- #endif
- theErr = Doc_Open( &theReply.sfFile ); // $$$$$ don't forget to handle errors.
- }
-
- if (theErr) Error_ReportOperationError (theErr);
-
- }
-
- //---------------------------------------------------------------------------
- // App_CloseMenu - close theWindow, first asking the user if they want to save
- // changes.
-
- void App_CloseMenu(
- WindowPtr theWindow )
- {
- WindowPtr aWindow;
- OSErr theErr;
- Boolean cancelled;
-
- theErr = Win_Close( theWindow, &cancelled );
-
- if (theErr) Error_ReportOperationError (theErr);
-
- if (!cancelled)
- {
- // Make sure the next window gets selected
- aWindow = App_GetFrontDocWindow();
- if (aWindow != nil)
- App_SetFrontDocWindow( aWindow );
- }
-
- }
-
- //---------------------------------------------------------------------------
- // App_SaveMenu - save theWindow's document.
-
- void App_SaveMenu(
- WindowPtr theWindow )
- {
- DocPtr theDoc;
- OSErr theErr;
-
- // if there is no window or it's not ours, get out.
- if (Win_IsAppWindow( theWindow ))
- {
- theDoc = (DocPtr)GetWRefCon( theWindow );
- theErr = Doc_Save( theDoc );
- if (theErr) Error_ReportOperationError (theErr);
- }
- }
-
- //---------------------------------------------------------------------------
- // App_SaveMenu - save theWindow's document under a new name.
-
- void App_SaveAsMenu(
- WindowPtr theWindow )
- {
- DocPtr theDoc;
- OSErr theErr;
-
- // if there is no window or it's not ours, get out.
- if (Win_IsAppWindow( theWindow ))
- {
- theDoc = (DocPtr)GetWRefCon( theWindow );
- theErr = Doc_SaveAs( theDoc );
- if (theErr) Error_ReportOperationError (theErr);
- }
- }
-
- //---------------------------------------------------------------------------
- // App_PageSetUpMenu -
-
- void App_PageSetUpMenu( WindowPtr theWindow )
- {
- DocPtr theDoc;
-
- // if there is no window or it's not ours, get out.
- if (!Win_IsAppWindow( theWindow ))
- return;
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
- if (!theDoc)
- return;
-
- App_ForceActivateFrontWindow( false );
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- if (!CARequestModalFocus( theWindow ))
- return;
- }
- #endif
-
- PrOpen();
- if (PrError())
- {
- Error_ShowMessage( kCASMsgNoPrinterSelected );
- return;
- }
-
- if (checkPrintHandle( &theDoc->hPrint ))
- {
- if (PrStlDialog( theDoc->hPrint ))
- Doc_SetDirty( theDoc, true );
- }
- else
- SysBeep(2);
- PrClose();
-
- #ifdef USE_CALIB
- if (gCALibExists)
- CARelinquishModalFocus( theWindow );
- #endif
-
- App_ForceActivateFrontWindow( true );
-
- // re-adjust zoomed size of window according to printer.
- Win_AdjustStdState( theWindow );
- }
-
- //---------------------------------------------------------------------------
-
- static void App_PreferencesMenu( void )
- {
- #define kSampleFlagItem 3
-
- Boolean prefSampleFlag;
- DialogPtr theDialog;
- GrafPtr savePort;
- short itemHit;
- WindowPtr frontWindow;
-
- GetPort( &savePort );
- App_ForceActivateFrontWindow( false );
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- frontWindow = CAGetFrontDocWindow();
- if (!CARequestModalFocus( frontWindow))
- return;
- }
- #endif
-
- prefSampleFlag = gPrefSampleFlag;
-
- //bSetCursorWatch();
-
- Dialog_CenterDLOGonFrontWindow( kPreferencesDialog );
- theDialog = GetNewDialog( kPreferencesDialog, nil, nil );
-
- if (theDialog == nil)
- return;
-
- SetPort( theDialog );
-
- // DAS: changed from ShowWindow.
- // show it, now that everything is ready.
- SelectWindow( (WindowPtr)theDialog );
- Dialog_OutlineButton( theDialog, 1 );
-
- //SetCursor(&qd.arrow);
-
- iOKITEM = kOKButton;
- iCancelITEM = kCancelButton;
- do
- {
- // set style check boxes each time through
- SetControlValue(
- (ControlHandle)Dialog_GetItemHandle( theDialog, kSampleFlagItem ),
- prefSampleFlag ? 1 : 0 );
-
- ModalDialog( gWindowEventFilterUPP, &itemHit );
-
- switch (itemHit)
- {
- case kSampleFlagItem:
- prefSampleFlag = !prefSampleFlag; // toggle the flag.
- break;
-
- default:
- break;
- }
- }
- while (itemHit != kOKButton && itemHit != kCancelButton);
-
- #ifdef USE_CALIB
- if (gCALibExists)
- CARelinquishModalFocus( frontWindow );
- #endif
-
- DisposeDialog( theDialog );
- App_ForceActivateFrontWindow( true );
- SetPort( savePort );
-
- // if it's OK button…
- if (itemHit == kOKButton)
- {
- gPrefChanged = true;
- gPrefSampleFlag = prefSampleFlag;
- }
- }
-
- // margins in pixels
- #define topMargin 0
- #define leftMargin 0
- #define rightMargin 0
- #define bottomMargin 0
-
- //---------------------------------------------------------------------------
- //
- void App_PrintWindow(
- WindowPtr theWindow )
- {
- Rect printRect;
- TPPrPort printPort;
- GrafPtr savePort;
- DocPtr theDoc;
- Rect theRect;
- Str255 windowTitle;
- DialogPtr printStatusDialog;
- long i;
- short count;
- ElemPtr elem;
-
- // if there is no window or it's not ours, get out.
- if (!Win_IsAppWindow( theWindow ))
- return;
-
- GetPort( &savePort );
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
- if (!theDoc)
- return;
-
- App_ForceActivateFrontWindow( false );
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- if (!CARequestModalFocus( theWindow ))
- {
- return;
- }
- }
- #endif
-
- // Put up a status dialog
- bSetCursorWatch();
- Dialog_CenterDLOGonFrontWindow( kPrintStatusDialog );
-
- printStatusDialog = GetNewDialog( kPrintStatusDialog, nil, nil );
-
- App_ForceActivateFrontWindow( false );
-
- SetPort( printStatusDialog );
- GetWTitle( theWindow, windowTitle );
- ParamText( windowTitle, nil, nil, nil );
- SelectWindow( (WindowPtr)printStatusDialog );
- DrawDialog( printStatusDialog );
-
- printPort = PrOpenDoc( theDoc->hPrint, nil, nil );
- SetPort( (GrafPtr)printPort );
- printRect = (**theDoc->hPrint).prInfo.rPage;
-
- // print page
- do
- {
- PrOpenPage( printPort, 0L );
-
- count = ElemColl_GetCount (theDoc->contentColl);
-
- // draw the content area here.
- for (i=1; i<=count; i++)
- {
- elem = ElemColl_GetNthElem (theDoc->contentColl, i);
- Elem_GetDisplayRect (elem, &theRect);
- if (RectInRgn( &theRect, theWindow->clipRgn ))
- Elem_Draw(elem, true);
- }
-
- PrClosePage( printPort );
-
- }
- while (0);
-
- PrCloseDoc( printPort );
-
- // Bring down status dialog
- DisposeDialog( printStatusDialog );
-
- #ifdef USE_CALIB
- if (gCALibExists)
- CARelinquishModalFocus( theWindow );
- #endif
- App_ForceActivateFrontWindow( true );
-
- SetPort( savePort );
- SetCursor( &qd.arrow );
- }
-
-
- //---------------------------------------------------------------------------
- // App_PrintMenu -
-
- void App_PrintMenu(
- WindowPtr theWindow )
- {
- GrafPtr savePort;
- TPrStatus prStatus;
- short copies;
- DocPtr theDoc;
-
- // if there is no window or it's not ours, get out.
- if (!Win_IsAppWindow( theWindow ))
- return;
-
- theDoc = (DocPtr)GetWRefCon( theWindow );
- if (!theDoc)
- return;
-
- App_ForceActivateFrontWindow( false );
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- if (!CARequestModalFocus( theWindow ))
- {
- return;
- }
- }
- #endif
-
- PrOpen();
- if (PrError() != noErr)
- {
- Error_ShowMessage( kCASMsgNoPrinterSelected );
- return;
- }
- if (checkPrintHandle(&theDoc->hPrint))
- {
- SetCursor( &qd.arrow );
- if (PrJobDialog( theDoc->hPrint ) != 0)
- {
- // PleaseWait();
- GetPort( &savePort );
- for (copies = howManyCopies( theDoc->hPrint ); copies > 0; copies--)
- {
- App_PrintWindow( theWindow );
- PrPicFile( theDoc->hPrint, 0L, 0L, 0L, &prStatus );
- }
- SetPort( savePort );
- }
- }
- PrClose();
-
- #ifdef USE_CALIB
- if (gCALibExists)
- CARelinquishModalFocus( theWindow );
- #endif
-
- App_ForceActivateFrontWindow( true );
- }
-
- //---------------------------------------------------------------------------
- // App_QuitMenu - close all the windows and set gExitFlag to true if the user
- // doesn't cancel.
-
- void App_QuitMenu( void )
- {
- gExitFlag = App_CloseAll();
- }
-
- //---------------------------------------------------------------------------
- // App_GetFrontFloater
-
- WindowPtr App_GetFrontFloater( void )
- {
- WindowPtr curFrontW;
-
- curFrontW = (WindowPtr)LMGetWindowList();
- if ((curFrontW != nil) && !Win_IsFloater( curFrontW ))
- curFrontW = nil;
-
- return curFrontW;
- }
-
- //---------------------------------------------------------------------------
- // App_GetBottomFloater
-
- WindowPtr App_GetBottomFloater( void )
- {
- WindowPtr curFrontW, nextW;
-
- curFrontW = (WindowPtr)LMGetWindowList();
- while (curFrontW != nil)
- {
- nextW = (WindowPtr)(((WindowPeek)curFrontW)->nextWindow);
- if ((nextW == nil) || !Win_IsFloater( nextW ))
- break;
-
- curFrontW = nextW;
- }
-
- if ((curFrontW != nil) && !Win_IsFloater( curFrontW ))
- curFrontW = nil;
-
- return curFrontW;
- }
-
- //---------------------------------------------------------------------------
- // App_GetFrontDocWindow
-
- WindowPtr App_GetFrontDocWindow( void )
- {
- WindowPtr curFrontW;
-
- #ifdef USE_CALIB
- if (gCALibExists)
- {
- curFrontW = CAGetFrontDocWindow();
- }
- else
- #endif
- {
- curFrontW = LMGetWindowList();
- while ( (curFrontW != nil) &&
- Win_IsFloater( curFrontW ) &&
- !Win_IsAppWindow( curFrontW) )
- curFrontW = (WindowPtr)(((WindowPeek)curFrontW)->nextWindow);
- }
- return curFrontW;
- }
-
- //---------------------------------------------------------------------------
- // App_SetFrontDocWindow
-
- void App_SetFrontDocWindow(
- WindowPtr targetWindow )
- {
- WindowPtr curFrontW, nextW;
-
- if ((targetWindow == nil) || !Win_IsVisible( targetWindow ) || Win_IsFloater( targetWindow ))
- return;
-
- #ifdef USE_CALIB
-
- CASelectWindow (targetWindow);
- return;
-
- #endif
-
- curFrontW = (WindowPtr)LMGetWindowList();
-
- if ((curFrontW == nil) || !Win_IsFloater( curFrontW ))
- SelectWindow( targetWindow );
- else
- {
- while ((curFrontW != nil) && Win_IsFloater( curFrontW ))
- {
- nextW = (WindowPtr)(((WindowPeek)curFrontW)->nextWindow);
- if ((nextW == nil) || !Win_IsFloater( nextW ))
- {
- SendBehind( targetWindow, curFrontW );
- CalcVis( (MODERN_WINDOW_REF)targetWindow );
- HiliteWindow( targetWindow, true );
-
- #if defined(_POST_ACTIVATE_EVENTS)
- Win_SendActivateEvent( targetWindow, true );
- #else
- if (!Win_IsToolWindow( targetWindow ))
- App_Activate( targetWindow );
- #endif
-
-
- if (nextW == targetWindow)
- nextW = (WindowPtr)(((WindowPeek)nextW)->nextWindow);
-
- if ((nextW != nil) && !Win_IsFloater( nextW ))
- {
- HiliteWindow( nextW, false );
-
- #if defined(_POST_ACTIVATE_EVENTS)
- Win_SendActivateEvent( nextW, false );
- #else
- if (!Win_IsToolWindow( targetWindow ))
- App_Deactivate( nextW );
- #endif
- }
-
- break;
- }
-
- curFrontW = (WindowPtr)(((WindowPeek)curFrontW)->nextWindow);
- }
- }
- }
-
- //---------------------------------------------------------------------------
- // App_ShowHideToolWindows
-
- void App_ShowHideToolWindows(
- Boolean showThem )
- {
- WindowPtr curFrontW;
-
- curFrontW = (WindowPtr)LMGetWindowList();
- while (curFrontW != nil)
- {
- if (Win_IsFloater( curFrontW ))
- Win_ShowHide( curFrontW, showThem );
-
- curFrontW = (WindowPtr)(((WindowPeek)curFrontW)->nextWindow);
- }
- }
-
- //---------------------------------------------------------------------------
- // Appl_ForceActivateFrontWindow
-
- void App_ForceActivateFrontWindow(
- Boolean makeActive )
- {
- WindowPtr curFrontDocW;
- GrafPtr savePort;
-
- curFrontDocW = App_GetFrontDocWindow();
- if (curFrontDocW != nil)
- {
- GetPort( &savePort );
- SetPort( (GrafPtr)curFrontDocW );
- HiliteWindow( curFrontDocW, makeActive );
- if (makeActive)
- App_Activate( curFrontDocW );
- else
- App_Deactivate( curFrontDocW );
- SetPort( savePort );
- }
- }
-
-